/**
 * 
 */
package pl.lodz.p.browarex.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity(name = "PRODUCT_ORDER")
public class ProductOrder {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(name = "PRODUCT_ID", nullable = false)
	private String productId;
	
	@Column(name = "GUID", nullable = false)
	private String productionID;
	
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="PRODUCTID", nullable = false, updatable = false)
	private Product product;
	
	@Column(name = "AMOUNT", nullable = false)
	private int amount;

	@Column(name = "REALIZATION", nullable = false)
	private boolean realization;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "DATE", nullable = false)
	private Date date;


	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getProductId() {
		return productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public Long getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + amount;
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result
				+ ((productId == null) ? 0 : productId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProductOrder other = (ProductOrder) obj;
		if (amount != other.amount)
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (productId == null) {
			if (other.productId != null)
				return false;
		} else if (!productId.equals(other.productId))
			return false;
		return true;
	}

	public String getProductionID() {
		return productionID;
	}

	public void setProductionID(String productionID) {
		this.productionID = productionID;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean isRealization() {
		return realization;
	}

	public void setRealization(boolean realization) {
		this.realization = realization;
	}

	@Override
	public String toString() {
		return "ProductOrder [id=" + id + ", productId=" + productId
				+ ", productionID=" + productionID + ", product=" + product
				+ ", amount=" + amount + ", date=" + date + "]";
	}



}
